package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.entity.po.Comment;
import com.project.entity.qo.CommentQo;
import com.project.result.ResponseResult;
import com.project.service.CommentService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName:
 * @Package:
 * @ClassName:
 * @Author: ZhaoLongShi
 * @CreateDate:
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentService commentService;


    /**
     * 评论
     *
     * @param commentQo
     * @return
     */
    @PostMapping("/comment")
    public ResponseResult comment(@RequestBody CommentQo commentQo) {
        ResponseResult result = commentService.comment(commentQo);
        return result;
    }

    /**
     * 查询所有评论（分页）
     *
     * @param current
     * @return
     */
    @RequiresRoles("admin")
    @GetMapping("/select/all/comment")
    public ResponseResult selectAllComment(int current,int size) {
            ResponseResult<Page<Comment>> result = commentService.selectComment(current,size);

        return result;
    }

    /**
     * 根据ID更新评论信息
     *
     * @param commentQo
     * @return
     */
    @RequiresRoles("admin")
    @PostMapping("/update/comment")
    public ResponseResult updateCommentById(@RequestBody CommentQo commentQo) {
        ResponseResult result = commentService.updateCommentById(commentQo);
        return result;
    }

    /**
     * 根据用户ID删除评论（可批量）
     *
     * @param idList
     * @return
     */
    @RequiresRoles("admin")
    @PostMapping("/delete/comment")
    public ResponseResult deleteCommentByIds(@RequestParam("idList") List<Long> idList) {
        ResponseResult result = commentService.deleteCommentByIds(idList);
        return result;
    }

    /**
     * 添加评论
     *
     * @param commentQo
     * @return
     */
    @RequiresRoles("admin")
    @PutMapping("/add/comment")
    public ResponseResult addComment(@RequestBody CommentQo commentQo) {
        ResponseResult result = commentService.addComment(commentQo);
        return result;
    }
}
